package com.moter.demo01.juc.jmm;

/**
 * 可以避免指令重排
 */
public class VolatileDemo3 {
    private static volatile int a = 0, b = 0, x, y;

    public static void main(String[] args) {

        new Thread(() -> {
            x = a;
            b = 1;
        }).start();
        new Thread(() -> {
            y = b;
            a = 2;
        }).start();
        System.out.println("a = " + a);
        System.out.println("b = " + b);
        System.out.println("x = " + x);
        System.out.println("y = " + y);
    }
}
